package com.blate.dogxiao.function;

import androidx.annotation.NonNull;

import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.ObservableTransformer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * RxJava自动Io调度器
 * 订阅在io线程
 * 观察在ui线程
 *
 * @author Az
 * on 2020/10/20
 */
public class AutoIoScheduler<T> implements ObservableTransformer<T, T> {

    @NonNull
    @Override
    public ObservableSource<T> apply(Observable<T> upstream) {
        return upstream
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }

}
